package cn.xdf.learn.future;


import java.util.Map;
import java.util.concurrent.CompletableFuture;

public class CompletableFutureTest {

    public static void main(String[] args) {

        long l1 = System.currentTimeMillis();

        CompletableFuture<String> strFuture = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "a";
        }).thenApply(s -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return s+="1";
        });

        CompletableFuture<String> strFuture2 = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "b";
        });

        CompletableFuture t = CompletableFuture.allOf(strFuture,strFuture2);
        t.join();

        System.out.println(System.currentTimeMillis() - l1);
        System.out.println(strFuture.join());
        System.out.println(strFuture2.join());
        System.out.println(System.currentTimeMillis() - l1);

    }

}
